package cn.gmcx.lazy.izze.service.impl;

import cn.gmcx.lazy.izze.mapper.UserMapper;
import cn.gmcx.lazy.izze.pojo.ToDo;
import cn.gmcx.lazy.izze.mapper.ToDoMapper;
import cn.gmcx.lazy.izze.service.IToDoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author GMCX
 * @since 2024-07-02
 */
@Service
public class ToDoServiceImpl extends ServiceImpl<ToDoMapper, ToDo> implements IToDoService {

    @Autowired
    private ToDoMapper mapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<ToDo> getToDoList(Integer userId) {
        List<ToDo> list = mapper.getToDoList(userId);
        return list;
    }

    @Override
    public Boolean addToDo(Integer masterId, String message, Integer followId,Integer type) {
        ToDo toDo = new ToDo();
        toDo.setMessage(message);
        toDo.setFollowId(masterId);
        toDo.setMasterId(followId);
        toDo.setType(type);
        int insert = mapper.insert(toDo);
        if(insert == 0){
            return false;
        }
        return true;
    }

    @Override
    public Boolean addToDoSuccess(Integer followId, String message) {
        ToDo toDo = new ToDo();
        toDo.setMessage(message);
        toDo.setMasterId(followId);
        int insert = mapper.insert(toDo);
        if(insert == 0){
            return false;
        }
        return true;
    }

    @Override
    public int DisposeKnow(Integer toDoId, Integer masterId, Integer status) {
        ToDo todo = new ToDo();
        todo.setId(toDoId);
        todo.setMasterId(masterId);
        todo.setStatus(status);
        return mapper.updateById(todo);
    }
}
